package com.zlkj.pro.modular.admin.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.zlkj.pro.modular.admin.model.dto.MaterialAdminDTO;
import com.zlkj.pro.modular.admin.model.vo.MaterialAdminVO;
import com.zlkj.pro.modular.admin.service.MaterialAdminService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.zlkj.pro.core.consts.ProjectConstants.BACKSTAGE_API_PREFIX;

/**
 * @author 孙铭泽
 * @date 2022/9/24
 * @time 14:34
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@ApiResource(name = "素材库管理", path = BACKSTAGE_API_PREFIX + "/material")
public class MaterialAdminController {

    private final MaterialAdminService materialAdminService;

    @GetResource(name = "分页查询", path = "/findPage")
    public ResponseData findPage(MaterialAdminDTO materialAdminDTO) {
        PageResult<MaterialAdminVO> restData = materialAdminService.findPage(materialAdminDTO);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "查询列表", path = "/findList")
    public ResponseData findList(MaterialAdminDTO materialAdminDTO) {
        List<MaterialAdminVO> restData = materialAdminService.findList(materialAdminDTO);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "查询详情", path = "/findDetail")
    public ResponseData findDetail(MaterialAdminDTO materialAdminDTO) {
        MaterialAdminVO restData = materialAdminService.findDetail(materialAdminDTO);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "添加", path = "/add")
    public ResponseData add(@RequestBody MaterialAdminDTO materialAdminDTO) {
        boolean restData = materialAdminService.add(materialAdminDTO);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "编辑", path = "/edit")
    public ResponseData edit(@RequestBody MaterialAdminDTO materialAdminDTO) {
        boolean restData = materialAdminService.edit(materialAdminDTO);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "删除", path = "/delete")
    public ResponseData delete(@RequestBody MaterialAdminDTO materialAdminDTO) {
        boolean restData = materialAdminService.delete(materialAdminDTO);
        return new SuccessResponseData(restData);
    }
}
